<!-- 新增、编辑 -->

<template>
  <el-dialog
    :model-value="dialogFormVisible"
    :destroy-on-close="true"
    title="游戏信息"
    width="450px"
    @close="emits('closeDialog')"
  >
    <el-form ref="dialogFormRef" :model="dialogForm">
      <el-form-item label="游戏名称" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.name" />
      </el-form-item>
      <el-form-item label="分值" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.score" />
      </el-form-item>

      <!-- <el-form-item label="版本号" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.version" />
      </el-form-item>
      <el-form-item label="slogan" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.slogan" />
      </el-form-item>
      <el-form-item label="游戏描述" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.desc" :rows="2" type="textarea" />
      </el-form-item>
      <el-form-item label="h5下载链接" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.h5_download_url" />
      </el-form-item>
      <el-form-item label="下载链接" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.download_url" />
      </el-form-item>

      <el-form-item label="h5游戏链接" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.h5_play_url" />
      </el-form-item> -->

      <el-form-item label="游戏背景图" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'mobybox' }"
          :show-file-list="false"
          :on-success="handleUploaderImgSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.img"
            :src="dialogForm.img_show"
            class="avatar"
          />
          <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="游戏封面图" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'mobybox' }"
          :show-file-list="false"
          :on-success="handleUploaderDetailImgSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.cover"
            :src="dialogForm.cover_show"
            class="avatar"
          />
          <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="游戏icon" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'mobybox' }"
          :show-file-list="false"
          :on-success="handleUploaderIconSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.icon"
            :src="dialogForm.icon_show"
            class="avatar"
          />
          <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="H5网址" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.h5_play_url" />
      </el-form-item>
      <el-form-item label="Slogan" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.slogan" />
      </el-form-item>
      <el-form-item label="版本号" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.version" />
      </el-form-item>
      <el-form-item label="版本内容" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.version_log" />
      </el-form-item>
      <el-form-item label="游戏介绍" :label-width="formLabelWidth">
        <el-input
          v-model="dialogForm.desc"
         
          :rows="2"
          type="textarea"
        />
      </el-form-item>
      <el-form-item label="H5下载地址" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.h5_download_url" />
      </el-form-item>
      <el-form-item label="下载地址" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.download_url" />
      </el-form-item>
      <el-form-item label="苹果下载地址" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.ios_download_url" />
      </el-form-item>
      <el-form-item label="安卓下载地址" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.android_download_url" />
      </el-form-item>
      <el-form-item label="安卓apk名称" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.android_apk_name" />
      </el-form-item>
      <el-form-item label="苹果ipa名称" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.ios_ipa_name" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(dialogForm)"
          :loading="btnLoading"
        >
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
import { uploadimgUrl } from "@/api/system/uploadimg";
import { TOKENT_HEADER } from "@/config/api-constant/system";
const dialogFormRef = ref(null);

defineProps({
  dialogFormVisible: {
    type: Boolean,
    default: false,
  },
  dialogForm: {
    type: Object,
    default: {
      name: "",
      score: "",
      img: "",
      img_show: "",
      cover: "",
      cover_show: "",
      icon: "",
      icon_show: "",
      h5_play_url: "",
      slogan: "",
      version: "",
      version_log: "",
      desc: "",
      h5_download_url: "",
      download_url: "",
      ios_download_url: "",
      android_download_url: "",
      android_apk_name: "",
      ios_ipa_name: "",
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits([
  "closeDialog",
  "cancel",
  "submitForm",
  "handleUploaderImgRequest",
]);

const formLabelWidth = "120px";

// 提交
const submit = (dialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        const param = { ...dialogForm };
        delete param.img_show;
        delete param.icon_show;
        delete param.cover_show;
        emits("submitForm", param);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
const handleUploaderIconSuccess = (res) => {
  emits("handleUploaderImgRequest", res, "icon", "icon_show");
};
const handleUploaderImgSuccess = (res) => {
  emits("handleUploaderImgRequest", res, "img", "img_show");
};
const handleUploaderDetailImgSuccess = (res) => {
  emits("handleUploaderImgRequest", res, "cover", "cover_show");
};
</script>
